import time
from Common.basepage import BasePage
from Common.handle_log import do_log
from PageLocators.MainPage_locator import MainPageLocator as loc
from Common.connect_to_device import d_one


class MainPage(BasePage):

    def click_home(self):
        height, width = d_one.window_size()
        # 1600 2560
        # 这里是横屏，所以反向
        d_one.click(width * 0.01, height * 0.94)
        do_log.info("点击左下角的首页按钮")
    def click_car(self):
        height, width = d_one.window_size()
        # 1600 2560
        # 这里是横屏，所以反向
        d_one.click(width * 0.5, height * 0.5)
        time.sleep(1)
        d_one.click(width * 0.101, height * 0.95)
        do_log.info("车机下方中控设置_点击车机设置(汽车图标)")
    def click_air_conditioner_loc(self):
        height, width = d_one.window_size()
        # 1600 2560
        # 这里是横屏，所以反向
        d_one.click(width * 0.5, height * 0.5)
        time.sleep(1)
        d_one.click(width * 0.493, height * 0.94)
        do_log.info("车机下方中控设置_点击车机设置(空调图标)")
    # def click_home(self):
    #     self.click_element(loc.home_loc, "点击左下角的首页按钮")
    #     do_log.info("点击左下角的首页按钮")

    def swipe_to_GEEKR_cinema(self):
        height, width = d_one.window_size()
        # 这里是横屏，所以反向
        d_one.swipe(width * 0.996, height // 2, 0, height // 2)
        do_log.info("左滑页面到极氪影院")

    def enter_film(self, filmname):
        self.click_element(loc.GEEKR_Cinema, "主页_点击5D专区")
        time.sleep(1)
        film_loc = loc.film_loc.replace("#film_name#", filmname)
        count = 0
        max_count = 3
        while not self.judge_ele_exists(film_loc) and count < max_count:
            self.swipe("up", "5D专区向上滑动屏幕")
            time.sleep(5)
            count += 1
        self.click_element(film_loc, "点击 {} 电影".format(filmname))

    def click_conditioner(self):
        self.click_element(loc.conditioner_loc, "点击空调设置")
        do_log.info("点击空调设置")


if __name__ == '__main__':
    # MainPage(device="d_one").click_home()
    # time.sleep(1)
    # MainPage(device="d_one").swipe_to_GEEKR_cinema()

    # time.sleep(3)
    MainPage(device="d_one").enter_film("封神第一部：朝歌风云")
